package com.seaboxdata.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;

public class TestShell {
    private static Logger log = LoggerFactory.getLogger(TestShell.class);

    private void callScript(String script, String args, String... workspace){
        Process process = null;
        try {
            String cmd = "sh " + script + " " + args;
            File dir = null;
            if(workspace[0] != null){
                dir = new File(workspace[0]);
                System.out.println(workspace[0]);
            }
//            String[] evnp = {"val=2", "call=Bash Shell"};
            log.info(dir + " start====");
            process = Runtime.getRuntime().exec(cmd, null, dir);
            BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line = "";
            while ((line = input.readLine()) != null) {
                log.info("line===={}",line);
            }
            input.close();
            log.info(dir + " end====");
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        TestShell call = new TestShell();
        call.callScript("restart.sh", "", "/software/ntcgps/");
    }
}
